package HuaweiOD;

import java.util.Arrays;
import java.util.Scanner;

public class 测试用例执行计划 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] fs = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            fs[i] = in.nextInt();
        }
        in.nextLine();

        int[][] tests = new int[m][2];
        for (int i = 0; i < m; i++) {
            tests[i][0] = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).map(id -> fs[id]).reduce(Integer::sum).orElse(0);
            tests[i][1] = i;
        }

        Arrays.sort(tests, (a, b) -> a[0] != b[0] ? b[0] - a[0] : a[1] - b[1]);

        for (int i = 0; i < m; i++) {
            System.out.println(tests[i][1] + 1);
        }
    }
}
